/**@author: Administrator
 * @date: 2013-3-5
 * @Description:
 */
package org.benxiong.iplay.ui;

import org.benxiong.iplay.R;
import org.benxiong.iplay.http.request.RequestFactory;
import org.benxiong.iplay.util.ToastUtil;
import org.json.JSONException;

import android.os.Message;
import android.view.Menu;
import android.view.MenuItem;

import com.loopj.android.http.AsyncHttpResponseHandler;

/**
 * @author Administrator
 * 
 */
public class ProfileInfoActivity extends BaseActivity {

	@Override
	protected void initView() {
		setContentView(R.layout.activity_profile);
		this.setActionBarLogoAsBackButton();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.benxiong.iplay.ui.BaseActivity#onMessage(android.os.Message)
	 */
	@Override
	public void onMessage(Message msg) {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.benxiong.iplay.ui.BaseActivity#handleClick(int)
	 */
	@Override
	public void handleClick(int buttonId) {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		getMenuInflater().inflate(R.menu.profile_menu, menu);
		super.onCreateOptionsMenu(menu);

		// MenuItem msgMenu = menu.add(0, 1, Menu.FIRST, "Message");
		// MenuItem favMenu = menu.add(0, 2, Menu.FIRST + 1, "Favorate");
		// msgMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
		// favMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		super.onOptionsItemSelected(item);
		switch (item.getItemId()) {
		case R.id.message:

			break;
		case R.id.fav:
		case R.id.block:
		case R.id.unlock:
		case R.id.meet:
			showLoading();
			String url = "";
			if (item.getItemId() == R.id.fav) {
				url = RequestFactory.URL_MEMBER_FAV;
			} else if (item.getItemId() == R.id.block) {
				url = RequestFactory.URL_MEMBER_BLOCK;
			} else if (item.getItemId() == R.id.unlock) {
				url = RequestFactory.URL_MEMBER_UNLOCK;
			} else if (item.getItemId() == R.id.block) {
				url = RequestFactory.URL_MEMBER_BLOCK;
			} else if (item.getItemId() == R.id.meet) {
				url = RequestFactory.URL_MEMBER_MEET;
			}

			RequestFactory.getInstance().post(url + "?username=" + getIntent().getStringExtra("username")
					, null, new AsyncHttpResponseHandler() {

						@Override
						public void onSuccess(String content) {
							// TODO Auto-generated method stub
							super.onSuccess(content);
							try {
								if (shouldProcess(content)) {
									ToastUtil.toast(R.string.operation_success);
								}
							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
						}

						@Override
						public void onFailure(Throwable error) {
							hideLoading();
							super.onFailure(error);
						}

					});
			break;
		case R.id.forward:

			break;

		}

		return true;
	}

}
